﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HtmlAgilityPack;
using Travan.ServerServices.CustomObjects;
using Travan.ServerServices.Interfaces;
using TravianAutoQueue.DomainModel;

namespace Travan.ServerServices
{
    public class TravianHelper : ITravianHelpers
    {

        #region ITravianHelpers Members
        public IHttpHelpers HttpHelper { get; set; }

        public bool CheckIfLoginPage(TravianSession session)
        {
            if (session.CurrentDocument.GetElementbyId("btn_login") == null)
                return false;
            
            return true;
        }

        public TravianSession Login(Account useraccount)
        {
            var Session = new TravianSession();
            Session.Username = useraccount.Username;
            Session.Password = useraccount.Password;
            Session.Server = useraccount.Server;
            return Login(Session);
        }

        #endregion

        public TravianSession Login(TravianSession Session)
        {
            var loginurl = string.Format("http://{0}/login.php", Session.Server);
            HttpHelper.Get(loginurl, Session);
            Session.FormValues["name"] = Session.Username;
            Session.FormValues["password"] = Session.Password;

            return HttpHelper.Post(string.Format("http://{0}/dorf1.php", Session.Server), Session);
        }

        
    }
}
